package com.corpgovernment.organization.dataloader;

import com.corpgovernment.api.flightintl.product.soa.FlightlntlOrderClient;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.common.dto.AllOrderBudgetRequestDto;
import com.corpgovernment.common.dto.AllOrderBudgetResponseDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

@Slf4j
@Component
public class IntlFlightClientLoader {

	@Autowired
	private FlightlntlOrderClient flightlntlOrderClient;

	public AllOrderBudgetResponseDto getFlightPassData(List<Long> orderList) {
		AllOrderBudgetRequestDto request = new AllOrderBudgetRequestDto();
		request.setOrderIds(orderList);

		JSONResult<AllOrderBudgetResponseDto> intlFlightOrderByOrderId = flightlntlOrderClient.getIntlFlightOrderByOrderId(request);

		if (intlFlightOrderByOrderId == null || intlFlightOrderByOrderId.getData() == null) {
			log.warn("查询支付单数据异常:" + Optional.ofNullable(intlFlightOrderByOrderId).map(JSONResult::getMsg).orElse("接口无响应"));
			return new AllOrderBudgetResponseDto();
		}
		return intlFlightOrderByOrderId.getData();
	}

}
